package cc.yaomm.service.basic.mapper.user;

import cc.yaomm.common.basic.base.SuperMapper;
import cc.yaomm.common.basic.enums.StatusEnum;
import cc.yaomm.common.biz.enums.OwnerTypeEnum;
import cc.yaomm.service.basic.entity.user.Permissions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Objects;

@Mapper
public interface PermissionsMapper extends SuperMapper<Permissions> {

    default List<Permissions> findByOwnerType(@Param("ownerType") OwnerTypeEnum ownerType, @Param("status") StatusEnum status) {
        LambdaQueryWrapper<Permissions> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Permissions::getOwnerType, ownerType);
        wrapper.eq(Objects.nonNull(status), Permissions::getStatus, status);
        return this.selectList(wrapper);
    }

    @Select("SELECT * FROM permissions WHERE owner_type = #{ownerType} AND code = #{code} limit 1")
    Permissions getByCode(@Param("code") String code, @Param("ownerType") OwnerTypeEnum ownerType);
}
